package com.woniuxy.service.impl;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.CheckProjectManage;
import com.woniuxy.mapper.CheckProjectManageMapper;
import com.woniuxy.service.CheckProjectManageService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import com.woniuxy.util.ResponseEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CheckProjectManageServiceImpl implements CheckProjectManageService , SaasService {


    @Resource
    private CheckProjectManageMapper checkProjectManageMapper;
    @Override
    public ResponseData<?> queryCheckProject(PageParam<CheckProjectManage> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());
        List<CheckProjectManage> checkProjectManageList = checkProjectManageMapper.queryList(pageParam.getParam());

        return new ResponseData<>().ok(new PageInfo<>(checkProjectManageList));
    }

    @Override
    public ResponseData<?> addCheckProject(CheckProjectManage checkProjectManage) {
        //判断必要值是否为空
        if (StringUtils.isBlank(checkProjectManage.getPjName())||checkProjectManage.getPjPrice()==null||
                StringUtils.isBlank(String.valueOf(checkProjectManage.getPjPrice()))||
                checkProjectManage.getPjDepartmentId() == null ||
            StringUtils.isBlank(String.valueOf(checkProjectManage.getPjDepartmentId()))){
            return new ResponseData<>().fail(ResponseEnum.MANDATORY_EMPTY);
        }

        checkProjectManageMapper.addCheckProject(checkProjectManage);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> queryCheckProjectById(Integer id) {
        CheckProjectManage checkProjectManage = checkProjectManageMapper.queryCheckProjectById(id);
        return new ResponseData<>().ok(checkProjectManage);
    }

    @Override
    public ResponseData<?> updateCheckProject(CheckProjectManage checkProjectManage) {
        //判断必要值是否为空
        if (StringUtils.isBlank(checkProjectManage.getPjName())||checkProjectManage.getPjPrice()==null||
                StringUtils.isBlank(String.valueOf(checkProjectManage.getPjPrice()))||
                checkProjectManage.getPjDepartmentId() == null ||
                StringUtils.isBlank(String.valueOf(checkProjectManage.getPjDepartmentId()))){
            return new ResponseData<>().fail(ResponseEnum.MANDATORY_EMPTY);
        }
        checkProjectManageMapper.updateCheckProject(checkProjectManage);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> deleteCheckProject(Integer id) {
        CheckProjectManage checkProjectManage = new CheckProjectManage();
        checkProjectManage.setId(id);
        checkProjectManage.setPjStatus("n");
        checkProjectManageMapper.updateCheckProject(checkProjectManage);
        return new ResponseData<>().ok();
    }
}
